package com.shelpe.services.sinbad.controller.dto;

import java.util.Date;

import org.apache.commons.lang3.StringUtils;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonFormat.Shape;
import com.shelpe.services.sinbad.entity.jpa.PurchaseOrder;
import com.shelpe.services.sinbad.entity.mongo.BlackList;
import com.shelpe.services.sinbad.utils.DateUtil;

import lombok.Data;

@Data
public class BlackUserDto {
	public final static String VERSION_SUPER = "FW_GOODS-1000041478-1";
	public final static String VERSION_GENERAL = "FW_GOODS-1000041478-v4";
	public final static String VERSION_ROBOT ="FW_GOODS-1000041478-v2";

	private String message;
	@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
	@JsonProperty("unsubscribe_time")
	private Date unsubscribeTime;// 退订时间
	private String nick;
	@JsonProperty("user_id")
	private long userID;

	private String channel;// 渠道
	private int fee;// 订购金额:分
	@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Shanghai")
	@JsonProperty("purchase_time")
	private Date purchaseTime;// 订购时间
	private int days; // 订购天数
	private String version;

	private boolean status;

	public BlackList to() {
		BlackList po = new BlackList();
		po.setMessage(this.message);
		return po;
	}

	public void from(BlackList po) {
		this.message = po.getMessage();
		this.unsubscribeTime = po.getCreateTime();
		this.nick = po.getNick();
		this.userID = po.getUserID();
		this.setStatus(true);
	}

	public void from(PurchaseOrder order){
		this.channel = "自订购";
		if(StringUtils.isNotBlank(order.getActivityCode())){
			this.channel = "其他";
		}
		this.fee = order.getPayFee()/100;
		this.purchaseTime = order.getOrderCycleStart();
		this.days = (int) DateUtil.convertBetweenDay(order.getOrderCycleStart(), order.getOrderCycleEnd());
		if(VERSION_SUPER.equals(order.getItemCode())){
			this.version = "旗舰版";
		}else if(VERSION_GENERAL.equals(order.getItemCode())){
			this.version = "基础版";
		}else if(VERSION_ROBOT.equals(order.getItemCode())){
			this.version = "人机版";
		}
		
	}
}
